import * as echarts from '../../ec-canvas/echarts';

const app = getApp();

function initChart(canvas, width, height) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height,
  });
  canvas.setChart(chart);

  var option = {
    title: {
      left: 'center'
    },
    fillerColor: ["#37A2DA", "", ""],
    color: ["#37A2DA", "#67E0E3", "#9FE6B8"],
    grid: {
      containLabel: true,
      left: '-30',
      top: '0',
      right: '0',
      bottom: '-18'
    },

    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
      show: false //是否显示x轴
    },
    yAxis: {
      x: 'center',
      type: 'value',
      max: 100, //最大刻度
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      },
      show: false //是否显示y轴
    },
    series: [{
      name: 'A',
      type: 'line',
      // areaStyle: {type:'default'},
      areaStyle: {
        normal: {
          color: new echarts.graphic.LinearGradient(
            0, 0, 1, 0,
            [
              { offset: 0, color: '#2F5DD9' },
              { offset: 1, color: '#3ACFD5' }
            ]
          )
        }
      },
      smooth: true,
      data: [50, 75, 62, 49, 51, 48, 28, 22, 32, 32, 31, 38]
    }]
    // 多条线在此添加
  };

  chart.setOption(option);
  return chart;
}
// pages/clss/clss.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ec: {
      onInit: initChart
    },
    selectBar: 0,
    selectMenu: [
      { id: '0', se: '最热' },
      { id: '1', se: '最新' },
      { id: '2', se: '全部' },
      { id: '3', se: '收益率' },
      { id: '4', se: '购买人数' },
      { id: '5', se: '交易种类' },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  select: function (e) {
    var that = this;
    var Bar = e.currentTarget.id;
    switch (Bar) {
      case '0':
        that.setData({
          selectBar: 0,
        });
        break;
      case '1':
        that.setData({
          selectBar: 1,
        });
        break;
      case '2':
        that.setData({
          selectBar: 2,
        });
        break;
      case '3':
        that.setData({
          selectBar: 3,
        });
        break;
      case '4':
        that.setData({
          selectBar: 4,
        });
        break;
      case '5':
        that.setData({
          selectBar: 5,
        });
        break;
    }
  },
})